package com.superman.supermarket.client.view.logistics;

import java.util.List;
import java.util.Map;

import com.google.gwt.core.client.GWT;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Widget;
import com.superman.mvpframe.client.mvp.IPageViewPresenter;
import com.superman.mvpframe.client.utils.XJsonUtil;
import com.superman.supermarket.client.composite.logistics.ExpressInfoModule;

/**
 * 物流ui实现
 * 
 * @author superman
 * @version 2018年8月15日下午2:31:54
 */
public class OrderLogisticsViewImpl extends Composite implements OrderLogisticsView {

	interface OrderLogisticsViewImplUiBinder extends UiBinder<Widget, OrderLogisticsViewImpl> {
	}

	private static OrderLogisticsViewImplUiBinder uiBinder = GWT.create(OrderLogisticsViewImplUiBinder.class);

	@UiField
	HTML expresscompanyhtml, expresstelhtml, expressnohtml;
	@UiField
	FlowPanel expresslistpanel;

	/**
	 * 构造方法
	 * 
	 * @author superman
	 * @version 2018年8月15日 下午2:31:51
	 */
	public OrderLogisticsViewImpl() {
		initWidget(uiBinder.createAndBindUi(this));
	}

	@Override
	public void init() {
	}

	@Override
	public void setOrderLogisticsList(Map<String, Object> map) {
		expresscompanyhtml.setHTML("快递公司:&nbsp;&nbsp;" + String.valueOf(map.get("COMPANY_NAME")));
		expresstelhtml.setHTML("官方电话:&nbsp;&nbsp;" + String.valueOf(map.get("PHONE")));
		expressnohtml.setHTML("快递号:&nbsp;&nbsp;" + String.valueOf(map.get("EXPRESS_NO")));

		expresslistpanel.setVisible(true);
		expresslistpanel.clear();

		if (map.get("LOGISTICS") == null) {
			HTML html = new HTML("暂无物流信息");
			expresslistpanel.add(html);
		} else {
			List<Map<String, Object>> list = XJsonUtil.getList((JSONArray) map.get("LOGISTICS"));
			for (int i = 0; i < list.size(); i++) {
				ExpressInfoModule expressInfoModule = new ExpressInfoModule();
				expressInfoModule.setData(list.get(i));
				expresslistpanel.add(expressInfoModule);
				if (i == 0)
					expressInfoModule.higtLight();
			}
		}
	}

	@Override
	public void setPageViewPresenter(IPageViewPresenter presenter) {
		// TODO Auto-generated method stub

	}

}
